<template>
  <div>
    <div>
      <FilterTable
        ref="recordTable"
        :columns="recordColumns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        :isColumnFilter=false
        :isToperInfo=false
        :isSelectColumn=false
        :onColumnsChange="columns => this.columns = columns"
        height='auto'
      />

    </div>

    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
    </div>

    <BaseDialog
      :visible.sync="visible"
      :title="'回访问卷'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <showQuestionnaire :questionnaireId="questionnaireId" :billType="billType" :billId="billId" @close="closeHandler"/>
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdate } from '@/utils/index';
import { getRecords } from '@/api/customerCare/saleVisit/downfeedback';
import showQuestionnaire from '../../tabs/showQuestionnaire.vue';

export default {
  name: 'DownfeedbackRecordModal',
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  components: {
    showQuestionnaire
  },
  data() {
    return {
      fetchParams: { 'billId': this.rowData.basalOrderId,'billType': 10421050 },
      fetchApi: getRecords,
      recordColumns: this.createRecordTableColumns(),
      visible: false,
      questionnaireId: '',
      billId: '',
      billType: ''
    }
  },
  computed: {},
  methods: {
    closeDialog(type) {
      this.$emit('close', false, type);
    },
    createRecordTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '问卷',
          dataIndex: 'column-action',
          width: 60,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.showHandle(props.row)}>
                  查看
                </el-button>
              </div>
            );
          }
        },
        {
          title: '回访时间',
          dataIndex: 'createdAt',
          render: props => {
            if(props.row.createdAt&&props.row.createdAt!=''){
              return <div>{formatdate(new Date(parseInt(props.row.createdAt)),1)}</div>;
            }
          }
        },
        {
          title: '回访人',
          dataIndex: 'createdBy'
        },
        {
          title: '回访类型',
          dataIndex: 'billType',
          render: props => {
            if(props.row.billType = 10421049){
              return <div>{'线索战败回访'}</div>;
            }else{
              return <div>{'基盘战败回访'}</div>;
            }
          }
        },
        {
          title: '回访内容',
          dataIndex: 'visitContent'
        }
      ];
    },
    closeHandler(val, type) {
      this.visible = val;
    },
    showHandle(row){
      this.visible = true;
      this.questionnaireId = row.questionnaireId;
      this.billType = 10421050;
      this.billId = row.billId;
    }
  },
  mounted() {
    this.BaseTable = this.$refs.recordTable.$refs.pageTable;
  }
};
</script>
